#include "stdafx.h"
#include "TextParser.h"

namespace AppliedCryptography
{
	std::vector<byte> TextParser::operator()(const char* input) const
	{
		return this->Encode(input);
	};

	std::vector<byte> TextParser::operator()(std::string& input) const
	{
		return this->Encode(input);
	};

	std::vector<byte> TextParser::Encode(const char* input) const
	{
		std::string str(input);
		return this->Encode(str);
	};

	std::vector<byte> TextParser::Encode(std::string& input) const
	{
		std::vector<byte> result;

		for(unsigned int i = 0; i < input.length(); ++i)
		{
			result.push_back( (byte) input.c_str()[i]);
		};

		return result;
	};

	std::string TextParser::operator()(std::vector<byte>& input) const
	{
		return this->Decode(input);
	};

	std::string TextParser::Decode(std::vector<byte>& input) const
	{
		std::string result;
		char arr[2];

		arr[1] = '\0';

		for(unsigned int i = 0; i < input.size(); ++i)
		{
			arr[0] = (char) input.at(i);
			result.append( arr );
		};

		return result;
	};
};
